<template>
  <div>
    <header class="header">
      <h1>todos</h1>
      <input class="new-todo" placeholder="请输入任务名称" autofocus v-model="value" @keyup.enter="increase(value)" />
    </header>
  </div>
</template>

<script>
export default {
  name: 'TodoListHeader',
  components: {},
  props: {},
  data() {
    return {
      value: ''
    }
  },
  computed: {},
  watch: {},
  created() {},
  methods: {
    // 回车添加功能
    increase(value) {
      // 空字符串不能添加
      if (!this.value) return alert('内容不能为空')
      this.$emit('increase', value)
      // 添加完后内容恢复为空
      this.value = ''
    }
  }
}
</script>

<style scoped></style>
